(function (aopc) {
    aopc.addExpandPage(792, function (get) {
        const Common = get('UtilsCommon', 'Common');
        const Bridge = get('UtilsCommon', 'Bridge');

        return {
            expandInit() {
                const left_view = this.getProperty('left_view');
                this.time_text = this.getViewProperty(left_view, 'time_text');
                this.date_text = this.getViewProperty(left_view, 'date_text');
                this.week_text = this.getViewProperty(left_view, 'week_text');
                const date_week_view2 = this.getProperty('date_week_view2');
                this.date_text2 = this.getViewProperty(date_week_view2, 'date_text2');
                this.week_text2 = this.getViewProperty(date_week_view2, 'week_text2');
                this.time_text2 = this.getProperty('time_text2');
                this.top_share_text = this.getProperty('top_share_text');
                //this.top_share_text.isVisible = !!window.sendSharingData;
                this.isIndex = true;
                this.screen_share_text1 = this.getProperty('screen_share_text1');
                this.add_share_screen_dialog = this.getProperty('add_share_screen_dialog');
                this.add_share_title = this.getViewProperty(this.add_share_screen_dialog, 'add_share_title');

                this.intervalId = setInterval(() => {
                    if (window.location.href.indexOf('index.html') > 0) this.showTime();
                    else clearInterval(this.intervalId);
                }, 1000 * 60);

                this.showTime();

                this.checkbox_view = this.getProperty('checkbox_view');
                this.checkbox_view.isChecked = true;
                this.checkbox_view.eventActionName = 'setCheckBoxChecked';

                this.share_type = this.getProperty('share_type');
                this.share_type.selectValue = 1;
                this.share_type.properties.forEach(p => {
                    p.eventActionName = "setShareType";
                });

                this.share_screen_dialog = this.getProperty('share_screen_dialog');
                this.end_share_screen_dialog = this.getProperty('end_share_screen_dialog');
                this.device_info_dialog_view = this.getProperty('device_info_dialog_view');
                this.meetingRoomIdProperty = this.getViewProperty(this.device_info_dialog_view, 'MeetingRoomId');
                this.meetingRoomIdProperty.valueChange = this.meetingRoomIdChange.bind(this);
                this.service_view = this.getViewProperty(this.device_info_dialog_view, 'service_view');
                this.displayIndexProperty = this.getViewProperty(this.device_info_dialog_view, 'DisplayIndex');

                if (this.pageData.sid) {
                    Common.setStorage('indexUrl', window.location.href);
                }
            },
            changeService() {
                Bridge.jsToNative('changeService');
            },
            meetingRoomIdChange(v, selectData, property) {
                if (!this.meetingRoomIdProperty.isChanged) return;

                if (window.sendSharingData) {
                    this.alert('正在共享屏幕中，请先结束共享');
                    return;
                }
                const view = this.meetingRoomIdProperty.getView();
                const { serviceName, actionName } = view.serviceInterface;

                const entityData = { MeetingRoomId: v };
                const url = 'Device/ChangeMeetingRoom';

                this.dispatchAction(serviceName, actionName, { url, Device: entityData }).then(res => {
                    if (res.isSuccess !== false) {
                        this.alertSuccess('切换成功', () => {
                            Bridge.jsToNative('changeMeetingRoom', {
                                MeetingRoomId: v,
                                DisplayIndex: res.DisplayIndex
                            }, () => window.location.reload());
                        });
                    }
                });
            },
            setAddShareTitle() {
                if (window.receSharingData) {
                    const { DisplayIndex } = window.receSharingData;
                    this.add_share_title.text = `设备${DisplayIndex}正在共享屏幕中......`;
                }
            },
            setInit() {
                const compayName = this.getProperty('CompanyName');
                compayName.text = this.visitUser.CompanyName;

                this.service_view.isVisible = this.visitUser.IsChangeService !== false;
                if (this.visitUser.IsChangeService === false) this.device_info_dialog_view.properties[0].style.height = '850rem';

                const { SendSharingData, ReceSharingData } = this.visitUser;
                if (!window.sendSharingData) window.sendSharingData = SendSharingData;
                if (!window.receSharingData) window.receSharingData = ReceSharingData;

                this.screen_share_text1.text = window.sendSharingData ? '结束共享' : window.receSharingData ? '加入共享' : '共享屏幕';
                this.setAddShareTitle();

                window.setEndReceShare = () => {
                    this.screen_share_text1.setValue(window.receSharingData ? '加入共享' : '共享屏幕');
                }

                window.setReceSharingData = (data) => {
                    if (this.isDestroy) return;
                    this.screen_share_text1.text = '加入共享';
                    this.screen_share_text1.setValue && this.screen_share_text1.setValue(this.screen_share_text1.text)
                };
            },
            setSelfHide({ property, e }) {
                const ele = property.getElement();
                if (ele === e.target) property.setIsVisible(false);
            },
            toQuickMeeting() {
                const url = `/quickMeeting.html?MeetingId=${Common.createGuid()}&backUrl=${encodeURIComponent('/index.html')}`;
                if (!this.getIsHost()) {
                    this.alert('无权限');
                    return;
                }
                this.toPage(url);
            },
            toSetSystem() {
                Bridge.jsToNative('toSetSystem')
            },
            showShare() {
                if (window.sendSharingData) {
                    this.end_share_screen_dialog.setIsVisible(true);
                    return;
                }
                else if (window.receSharingData) {
                    const { DisplayIndex, ShareType } = window.receSharingData;
                    if (ShareType === 2) {
                        this.alert(`设备${DisplayIndex}正在共享大屏中`);
                        return
                    }
                    this.setAddShareTitle();
                    this.add_share_screen_dialog.setIsVisible(true);
                    return;
                }
                else if (!this.getIsHost()) {
                    this.alert('无权限');
                    return;
                }
                this.showShareDialog();
            },
            addShare() {
                if (!window.receSharingData) {
                    this.alert('共享已结束');
                    this.add_share_screen_dialog.setIsVisible(false);
                    return;
                }
                if (this.isAdding) return;
                this.isAdding = true;

                Bridge.receiveStartShare(window.receSharingData);
                this.add_share_screen_dialog.setIsVisible(false);

                setTimeout(() => {
                    this.isAdding = false;
                }, 3000);
            },
            showShareDialog() {
                this.share_screen_dialog.setIsVisible(true);
            },
            setShareType({ property }) {
                this.share_type.properties.forEach((p, i) => {
                    if (property === p) {
                        p.style.backgroundColor = '#ffffff';
                        if (this.theme === 'red') {
                            p.style.border = '2rem solid #EA0000';
                            p.properties[0].spanStyle.color = '#EA0000';
                        }
                        else {
                            p.style.border = '2rem solid #5B93DD';
                            p.properties[0].spanStyle.color = '#5B93DD';
                        }
                        p.style.boxShadow = '0px 17rem 29rem 0px rgba(0,120,251,0.0902)';
                        p.properties[1].setIsVisible(true);
                        this.share_type.selectValue = i + 1;
                    }
                    else {
                        p.style.backgroundColor = 'rgba(255,255,255,0.6)';
                        if (this.theme === 'red') {
                            p.style.border = '2rem solid #FFC8C8';
                        }
                        else {
                            p.style.border = '2rem solid #ADD3F2';
                        }
                        p.style.boxShadow = '';
                        p.properties[0].spanStyle.color = '#2a2a2a';
                        p.properties[1].setIsVisible(false);
                    }
                    p.refresh();
                    p.properties[0].refresh();
                });
            },
            setCheckBoxChecked({ property }) {
                property.isChecked = !property.isChecked;
                const p = property.properties[0];
                if (this.theme === 'red') p.imgUrl = property.isChecked ? 'images/yxinmt_h5/25081717403418045.png' : 'images/yxinmt_h5/25081717463559515.png';
                else p.imgUrl = property.isChecked ? 'images/yxinmt_h5/24122621131417447.png' : 'images/yxinmt_h5/24122621203283353.png';
                p.setValue(p.imgUrl);
            },
            showTime() {
                const date = new Date();
                let hh = date.getHours();
                hh = hh < 10 ? `0${hh.toString()}` : hh.toString();
                let mm = date.getMinutes();
                mm = mm < 10 ? `0${mm.toString()}` : mm.toString();

                let month = (date.getMonth() + 1);
                let day = date.getDate();

                this.setValue(this.date_text, `${month}月${day}日`);
                this.setValue(this.date_text2, `${month}月${day}日`);
                this.setValue(this.time_text, hh + ":" + mm);
                this.setValue(this.time_text2, hh + ":" + mm);
                this.setValue(this.week_text, Common.getWeek(date));
                this.setValue(this.week_text2, Common.getWeek(date));
            },
            showDeviceInfo() {
                this.setDeviceInfo();
                this.device_info_dialog_view.setIsVisible(true);
            },
            setDeviceInfo() {
                this.meetingRoomIdProperty.isChanged = false;
                const p2 = this.device_info_dialog_view.properties[0];
                const { DisplayIndex, IsPresident, MacAddress, MeetingRoomId, VersionTime } = this.visitUser;
                const data = { DisplayIndex, MacAddress: MacAddress || '未知', VersionTime, ServiceUrl: window.location.host, RoleName: IsPresident ? '主席' : '参与者', MeetingRoomId };
                this.eventActions.entityEdit.setPropertiesValue(p2.properties, data, true, true);
            },
            setValue(p, v) {
                p.value = v;
                p.setValue && p.setValue(v);
            },
            setMinWin() {
                Bridge.setMinWin();
            },
            closeWin() {
                if (window.sendSharingData) {
                    this.alert('正在共享屏幕中，请先结束共享');
                    return;
                }
                Bridge.closeWin();
            },
            startShare() {
                if (this.isStartShare) return;
                this.isStartShare = true;

                const { isChecked } = this.checkbox_view;
                const { selectValue } = this.share_type;

                Bridge.startShare(selectValue, isChecked, (data) => {
                    this.share_screen_dialog.setIsVisible(false);
                    this.isStartShare = false;

                    this.webSocket.send('startShare', data);
                    this.showTopShareText(true);
                    this.screen_share_text1.setValue('结束共享');
                    window.sendSharingData = data;
                });
            },
            showTopShareText(visible) {
                //this.top_share_text.setIsVisible(visible);
            },
            showEndShareDialog() {
                this.end_share_screen_dialog.setIsVisible(true);
            },
            endShare() {
                if (this.isEndShare) return;
                this.isEndShare = true;

                Bridge.endShare(() => {
                    this.end_share_screen_dialog.setIsVisible(false);
                    this.isEndShare = false;

                    this.webSocket.send('endShare');
                    this.showTopShareText(false);
                    this.screen_share_text1.setValue('共享屏幕');
                    window.sendSharingData = null;
                });
            }
        }
    });
})(window.aopc);